package org.openfans.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.openfans.domain.Facade;
import org.openfans.domain.Fans;
import org.openfans.domain.PreFans;
import org.openfans.domain.RootTag;
import org.openfans.util.ThreadFans;
import org.openfans.util.WebUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.BaseCommandController;

/**
 * 
 * Desc：<br>
 * Date：2007-5-14<br>
 * 
 * @author pesome<br>
 * @email:pesome@gmail.com<br>
 */
public class DiggController extends BaseCommandController {
	private Facade facade;

	public void setFacade(Facade facade) {
		this.facade = facade;
	}

	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		WebUtil.letNoCache(response);
		String type = request.getParameter("type");
		String id = request.getParameter("id");
		if ("tag".equals(type)) {
			RootTag tag = (RootTag) facade.getTag(Integer.parseInt(id));
			Fans fans = ThreadFans.get();
			if (fans instanceof PreFans) {
				response.getWriter().print("error");
			} else {
				fans=facade.getFans(fans.getFansId());
				facade.digg(tag, fans);
				response.getWriter().print("ok");
			}
		}else{
			response.getWriter().print("error");
		}
		return null;
	}
}
